package com.wy.allthingdone.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wy.allthingdone.R;

import org.xutils.view.annotation.ViewInject;

import java.io.File;
import java.util.ArrayList;

public class RecyclerListActivity extends BaseActivity {
    @ViewInject(R.id.recycleView)
    RecyclerView recycleView;
    private RecyclerView.Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_recycler_list);
        super.onCreate(savedInstanceState);
        list = showFileDir(ROOT_PATH);
        Log.i("TAG", list.toString());
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new RecyclerView.Adapter() {

            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, null));
            }

            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
                MyViewHolder viewHolder = (MyViewHolder) holder;
                viewHolder.getText().setText(list.get(position).toString());
            }

            @Override
            public int getItemCount() {
                return list.size();
            }

            class MyViewHolder extends RecyclerView.ViewHolder {
                private TextView text;

                public MyViewHolder(View itemView) {
                    super(itemView);
                    this.text = (TextView) itemView.findViewById(R.id.text);
                }

                public TextView getText() {
                    return text;
                }
            }
        };
        recycleView.setAdapter(adapter);
    }

    private ArrayList<String> mFileName;
    private ArrayList<String> mFilePath;
    public static String ROOT_PATH = "/";
    private ArrayList<String> list;

    String[] str = new String[]{
            "/ sdcard",
            "/custom",
            "/protect_s",
            "/protect_f",
            "/storage",
            "/config",
            "/cache",
            "/acct",
            "/vendor",
            "/d",
            "/etc",
            "/var",
            "/mnt",
            "/unlock_key",
            "/ueventd.rc",
            "/system",
            "/sys",
            "/service_contexts",
            "/sepolicy",
            "/selinux_version",
            "/seapp_contexts",
            "/sbin",
            "/property_contexts",
            "/proc",
            "/meta_init.rc",
            "/meta_init.project.rc",
            "/meta_init.modem.rc",
            "/init.zygote64_32.rc",
            "/init.zygote32.rc",
            "/init.xlog.rc",
            "/init.usb.rc",
            "/init.trace.rc",
            "/init.storage.rc",
            "/init.ssd.rc",
            "/init.recovery.hardware.rc",
            "/init.rc",
            "/init.project.rc",
            "/init.mt6795.usb.rc",
            "/init.mt6795.rc",
            "/init.mt6595.rc",
            "/init.modem.rc",
            "/init.miui8.rc",
            "/init.miui.rc",
            "/init.environ.rc",
            "/init.aee.rc",
            "/init",
            "/fstab.mt6795",
            "/fstab.charger",
            "/file_contexts",
            "/factory_init.rc",
            "/factory_init.project.rc",
            "/enableswap.sh",
            "/default .prop",
            "/data",
            "/charger",
            "/bin",
            "/root",
            "/dev"
    };

    /**
     * 扫描显示文件列表
     *
     * @param path
     */
    private ArrayList<String> showFileDir(String path) {
        mFileName = new ArrayList<String>();
        mFilePath = new ArrayList<String>();
        File file = new File(path);

        File[] files = file.listFiles();
        //如果当前目录不是根目录
        if (!ROOT_PATH.equals(path)) {
            mFileName.add("@1");
            mFilePath.add(ROOT_PATH);
            mFileName.add("@2");
            mFilePath.add(file.getParent());
        }
        ArrayList<String> list = new ArrayList<String>();
        Log.i("TAG", "files==========" + files.length);
        //添加所有文件
//        for (File f : files) {
//            mFileName.add(f.getName());
//            mFilePath.add(f.getPath());
//            if (!f.getPath().trim().equals("/")) {
//                list.add(f.getPath());
//            }
//        }
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        return list;
    }
}
